// WizardExportLast.cpp : implementation file
//

#include "stdafx.h"
#include "calendar.h"
#include "WizardExportLast.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CWizardExportLast property page

IMPLEMENT_DYNCREATE(CWizardExportLast, CPropertyPage)

CWizardExportLast::CWizardExportLast() : CPropertyPage(CWizardExportLast::IDD),
	m_btnBrowse(IDB_BROWSE, IDB_BROWSE, CSize(21,21))
{
	//{{AFX_DATA_INIT(CWizardExportLast)
	m_bExportFile = FALSE;
	m_bExportCb = FALSE;
	//}}AFX_DATA_INIT
}

CWizardExportLast::~CWizardExportLast()
{
}

void CWizardExportLast::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CWizardExportLast)
	DDX_Control(pDX, IDC_EDIT1, m_eFile);
	DDX_Control(pDX, IDC_BROWSE, m_btnBrowse);
	DDX_Check(pDX, IDC_EXPORT_FILE, m_bExportFile);
	DDX_Check(pDX, IDC_EXPORT_CB, m_bExportCb);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CWizardExportLast, CPropertyPage)
	//{{AFX_MSG_MAP(CWizardExportLast)
	ON_BN_CLICKED(IDC_EXPORT_FILE, OnExportFile)
	ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWizardExportLast message handlers

BOOL CWizardExportLast::OnSetActive() 
{
	CPropertySheet *pSheet = (CPropertySheet *) GetParent();
	pSheet->SetWizardButtons(PSWIZB_FINISH | PSWIZB_BACK);
	
	return CPropertyPage::OnSetActive();
}

BOOL CWizardExportLast::OnWizardFinish() 
{
	UpdateData(true);
	CString path;
	m_eFile.GetWindowText(path);

	if(m_bExportCb && m_bExportFile) {
		calendar.Export(Calendar::EXPORT_ALL, path);
	} else if(m_bExportCb && !m_bExportFile) {
		calendar.Export(Calendar::EXPORT_CLIPBOARD);
	} else if(!m_bExportCb && m_bExportFile) {
		calendar.Export(Calendar::EXPORT_FILE, path);
	}
	
	return CPropertyPage::OnWizardFinish();
}

void CWizardExportLast::OnExportFile() 
{
	UpdateData(true);

	m_eFile.EnableWindow(m_bExportFile);
	m_btnBrowse.EnableWindow(m_bExportFile);
}

BOOL CWizardExportLast::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	
	m_bExportCb = true;
	
	UpdateData(false);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CWizardExportLast::OnBrowse() 
{
	CFileDialog fileDlg(FALSE, ".xml", "calendar.xml", 
		OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
		"XML file (*.xml) | *.xml||");

	if( fileDlg.DoModal() == IDOK )	{
		m_eFile.SetWindowText(fileDlg.GetPathName());

		UpdateData(false);
	}
	
}
